package com.xboss.tv.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import android.widget.Toast;

/**
 * Created by Administrator on 2017\7\21 0021.
 */

public class CustomLinearLayout extends LinearLayout {

    private final Context mContext;

    public CustomLinearLayout(Context context) {
        this(context,null,0);
    }
    public CustomLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }
    public CustomLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_CENTER:
                Toast.makeText(mContext,"你按下中间键",Toast.LENGTH_SHORT).show();
                break;
            case KeyEvent.KEYCODE_ENTER:
                Toast.makeText(mContext,"你按下中间键",Toast.LENGTH_SHORT).show();
                break;

            case KeyEvent.KEYCODE_DPAD_DOWN:
                Toast.makeText(mContext,"你按下下方向键",Toast.LENGTH_SHORT).show();
                break;

            case KeyEvent.KEYCODE_DPAD_LEFT:
                Toast.makeText(mContext,"按下左方向键",Toast.LENGTH_SHORT).show();
                break;

            case KeyEvent.KEYCODE_DPAD_RIGHT:
                Toast.makeText(mContext,"你按下右方向键",Toast.LENGTH_SHORT).show();
                break;

            case KeyEvent.KEYCODE_DPAD_UP:
                Toast.makeText(mContext,"你按下上方向键",Toast.LENGTH_SHORT).show();
                break;
        }
        return super.onKeyDown(keyCode, event);
    }
}
